<template>
  <!-- 财务管理 begin -->
  <div class="main" id="main_finance_manager">
    <div class="main-hd">
      <h2>模型统计</h2>
    </div>
    <div class="main-bd">
      <div class="content-wrap" id="VuePayment_content">
        <Tabs @on-click="banben">
          <TabPane label="贷前数据统计"></TabPane>
          <TabPane label="贷中数据统计"></TabPane>
        </Tabs>
        <DatePicker type="daterange" format="yyyy-MM-dd" :options="disDate" @on-change="timeChange" placeholder="Select date" style="width: 200px;margin-bottom:20px;"></DatePicker>
        <Table border :columns="utColumns" :data="utList" :loading="utLoading"></Table>
      </div>
    </div>
  </div>
</template>
<script>
  import qs from 'qs';
  export default {
    name: 'modelStatistics',
    data () {
      return {
        billStatDetailModal: false,
        switchStatus: false,
        beginDate: '',
        endDate: '',
        tabIndex: 0
,        repayForm: {},
        utList: [],
        disDate: {
					disabledDate (date) {
					return date && date.valueOf() > Date.now();
					}
				},
        utColumns: [
          { title: '模型名称', key: 'riskModelName' },
          { title: '审核数', key: 'applyCount'},
          { title: '通过数',key: 'applySuccessCount' },
          { title: '通过率',key: 'applySuccessRate',
            render: (h, params) => {
              return h('div', params.row.applySuccessRate ? (params.row.applySuccessRate*100).toFixed(2)+'%' : 0)
            } 
          },
          { title: '放款数',key: 'orderCount' },
          { title: '自然回款数',key: 'naturalRepayCount' },
          { title: '自然回款率',key: 'naturalRepayRate',
            render: (h, params) => {
              return h('div', params.row.naturalRepayRate ? (params.row.naturalRepayRate*100).toFixed(2)+'%' : 0)
            } 
          },
          { title: '回款数',key: 'repayCount' },
          { title: '回款率',key: 'repayRate',
            render: (h, params) => {
              return h('div', params.row.repayRate ? (params.row.repayRate*100).toFixed(2)+'%' : 0)
            } 
          },
          // { 
          //   title: '更新时间',
          //   key: 'utime',
          //   render: (h, params) => {
          //     var d = new Date(params.row.utime);
          //     return h('div', [ [ d.getFullYear(), d.getMonth() + 1, d.getDate(), '-'], [ d.getHours(), d.getMinutes(), d.getSeconds(), ':'] ]
          //     .map(arr => {
          //       var split = arr.pop();
          //       return arr.map(val => val > 9 ? val : '0' + val).join(split);
          //     }).join(' '))
          //   }
          // }
        ],
        utLoading: true,
        pageSize: 10,
        page: 1,
        total: 0
      }
    },
    created () {
      this.getModelStatistics();
    },
    methods: {
      banben(e){
        e == 0 ? this.tabIndex = 0 : this.tabIndex = 1;
        this.getModelStatistics();
			},
      // 模型统计
      getModelStatistics () {
        let riskModelType = this.tabIndex == 0 ? 'preLoan' : 'inLoan';
        this.$http.get('/helsinki/admin/report/getRiskModelStat?endDate='+this.endDate+'&beginDate='+this.beginDate+'&riskModelType='+riskModelType)
        .then((data) => {
          if (data.body.errcode == 0) {
            this.utList = data.body.data.list;
          }
          this.utLoading = false;
        }, error => {
          // this.$Message.info(error);
        });
      },
      timeChange(e){
				if(typeof(e)=="undefined"){
					this.beginDate = e[0];
				}else if(typeof(e)=="object"){
					this.beginDate = e[0];
					this.endDate = e[1];
				}
				this.getModelStatistics();
			}
    }
  }
</script>
